﻿using System;
namespace Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="volgnik_jada_item", Namespace="http://producers.taitis.xtee.riik.ee/producer/taitis", Target=typeof(VolgnikJadaItem))]
    public class VolgnikJadaItemSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IVolgnikJadaItem clazz;
        
        public VolgnikJadaItemSerializer(IVolgnikJadaItem clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("volgniku_kood");
            if (clazz.VolgnikuKood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.VolgnikuKood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : VolgnikuKood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("volgniku_eesnimi");
            if (clazz.VolgnikuEesnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.VolgnikuEesnimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : VolgnikuEesnimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("volgniku_nimi");
            if (clazz.VolgnikuNimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.VolgnikuNimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : VolgnikuNimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("volgniku_synnipaev");
            if (clazz.VolgnikuSynnipaev!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.VolgnikuSynnipaev))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : VolgnikuSynnipaev");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("volgniku_synnikuu");
            if (clazz.VolgnikuSynnikuu!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.VolgnikuSynnikuu))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : VolgnikuSynnikuu");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("volgniku_synniaasta");
            if (clazz.VolgnikuSynniaasta!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.VolgnikuSynniaasta))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : VolgnikuSynniaasta");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("toimik4_jada");
            if (clazz.Toimik4Jada!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("toimik4", "http://producers.taitis.xtee.riik.ee/producer/taitis", clazz.Toimik4Jada.Count);
                for (int x = 0; ((clazz.Toimik4Jada != null) 
                            && (x < clazz.Toimik4Jada.Count)); x = (x + 1)) {
                    if (clazz.Toimik4Jada[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaToimik4Jada = this.GetMetaData(clazz.Toimik4Jada[x]);
                        Writer.WriteTypeAttribute(metaToimik4Jada.TypeQualifiedName.Namespace, metaToimik4Jada.TypeQualifiedName.Name);
                        metaToimik4Jada.NewSerializer(clazz.Toimik4Jada[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Toimik4Jada");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "volgniku_kood")) {
                goto volgniku_kood;
            }
            else {
                if ((Reader.LocalName == "volgniku_eesnimi")) {
                    goto volgniku_eesnimi;
                }
                else {
                    if ((Reader.LocalName == "volgniku_nimi")) {
                        goto volgniku_nimi;
                    }
                    else {
                        if ((Reader.LocalName == "volgniku_synnipaev")) {
                            goto volgniku_synnipaev;
                        }
                        else {
                            if ((Reader.LocalName == "volgniku_synnikuu")) {
                                goto volgniku_synnikuu;
                            }
                            else {
                                if ((Reader.LocalName == "volgniku_synniaasta")) {
                                    goto volgniku_synniaasta;
                                }
                                else {
                                    if ((Reader.LocalName == "toimik4_jada")) {
                                        goto toimik4_jada;
                                    }
                                    else {
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        volgniku_kood:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>volgnik_jada_item>volgniku_kood");
            }
            clazz.VolgnikuKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("volgniku_kood")).Value;
            goto START;
        volgniku_eesnimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>volgnik_jada_item>volgniku_eesnimi");
            }
            clazz.VolgnikuEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("volgniku_eesnimi")).Value;
            goto START;
        volgniku_nimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>volgnik_jada_item>volgniku_nimi");
            }
            clazz.VolgnikuNimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("volgniku_nimi")).Value;
            goto START;
        volgniku_synnipaev:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>volgnik_jada_item>volgniku_synnipaev");
            }
            clazz.VolgnikuSynnipaev = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("volgniku_synnipaev")).Value;
            goto START;
        volgniku_synnikuu:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>volgnik_jada_item>volgniku_synnikuu");
            }
            clazz.VolgnikuSynnikuu = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("volgniku_synnikuu")).Value;
            goto START;
        volgniku_synniaasta:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>volgnik_jada_item>volgniku_synniaasta");
            }
            clazz.VolgnikuSynniaasta = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("volgniku_synniaasta")).Value;
            goto START;
        toimik4_jada:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>volgnik_jada_item>toimik4_jada");
            }
            clazz.Toimik4Jada = new System.Collections.Generic.List<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IToimik4>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("toimik4_jada");
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "item")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>volgnik_jada_item>toimik4_jada>item");
                    }
                    global::Xtee.Core.SerializationMetadata metaToimik4Jada = this.GetMetaData<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IToimik4>(Reader, "toimik4", "http://producers.taitis.xtee.riik.ee/producer/taitis");
                    global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IToimik4 item = metaToimik4Jada.NewEntity<global::Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis.IToimik4>();
                    clazz.Toimik4Jada.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("item");
                        metaToimik4Jada.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
    }
}
